package org.example.config;

import org.example.config.TenantInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 * 注册拦截器等
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    
    @Autowired
    private TenantInterceptor tenantInterceptor;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册租户拦截器，处理企业端和用户端的companyId解析
        registry.addInterceptor(tenantInterceptor)
                .addPathPatterns("/**/enterprise/**", "/**/user/**")  // 支持API前缀
                .excludePathPatterns(
                    "/**/enterprise/auth/login",     // 企业端登录
                    "/**/user/auth/login",           // 用户端登录
                    "/**/enterprise/sms/**",         // 企业端验证码
                    "/**/user/sms/**",               // 用户端验证码
                    "/**/sms/**"                     // 所有验证码接口
                );
        
        System.out.println("=== 租户拦截器注册成功 ===");
        System.out.println("拦截路径: /**/enterprise/**, /**/user/**");
        System.out.println("排除路径:");
        System.out.println("  - /**/enterprise/auth/login (企业端登录)");
        System.out.println("  - /**/user/auth/login (用户端登录)");
        System.out.println("  - /**/enterprise/sms/** (企业端验证码)");
        System.out.println("  - /**/user/sms/** (用户端验证码)");
        System.out.println("  - /**/sms/** (所有验证码)");
    }
}


















